package com.gxa.employment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.employment.entity.dto.EnterpriseDto;

import com.gxa.employment.entity.vo.EnterpriseEmploymentVo;
import com.gxa.employment.entity.vo.PageVo;
import com.gxa.employment.mapper.EnterpriseEmploymentVoMapper;
import com.gxa.employment.service.EnterpriseEmploymentVoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class EnterpriseEmploymentVoServiceImpl extends ServiceImpl<EnterpriseEmploymentVoMapper, EnterpriseEmploymentVo> implements EnterpriseEmploymentVoService {

    @Override
    @Transactional
    public PageVo<EnterpriseEmploymentVo> selectEntEmp(EnterpriseDto enterpriseDto) {
        // 创建LambdaQueryWrapper对象
        LambdaQueryWrapper<EnterpriseEmploymentVo> queryWrapper = Wrappers.lambdaQuery(EnterpriseEmploymentVo.class);
        // 根据enterpriseDto中的entName进行条件查询
        queryWrapper.like(StringUtils.isNotEmpty(enterpriseDto.getEntName()),EnterpriseEmploymentVo::getEntName,enterpriseDto.getEntName())
                // 根据enterpriseDto中的jobTitle进行条件查询
                .like(StringUtils.isNotEmpty(enterpriseDto.getJobTitle()),EnterpriseEmploymentVo::getJobTitle, enterpriseDto.getJobTitle())
                // 按创建时间降序排序
                .orderByDesc(EnterpriseEmploymentVo::getCreated);

        // 创建Page对象，设置分页参数
        IPage<EnterpriseEmploymentVo> employmentVoPage = new Page<>(enterpriseDto.getPage(),enterpriseDto.getSize());
        // 执行分页查询
        this.page(employmentVoPage,queryWrapper);

        // 获取总记录数
        long total = employmentVoPage.getTotal();
        // 获取查询结果列表
        List<EnterpriseEmploymentVo> records = employmentVoPage.getRecords();

        // 返回PageVo对象
        return new PageVo<>(total,records);
    }

}
